<template>
	<view style="margin: 15px;background: #fff;border-radius: 15px;padding: 10px;">
		<u-form labelPosition="left" :model="model1" :rules="rules" labelWidth="90" ref="form1">
			<u-form-item label="绑定用户ID" prop="userInfo.id" borderBottom ref="item1">
				<u-input v-model="model1.userInfo.id" borderBottom></u-input>
			</u-form-item>

			<u-form-item label="姓名" prop="userInfo.name" borderBottom ref="item1">
				<u-input v-model="model1.userInfo.name" borderBottom></u-input>
			</u-form-item>

			<u-form-item label="手机号" prop="userInfo.password" borderBottom ref="item1">
				<u-input v-model="model1.userInfo.mobile"></u-input>
			</u-form-item>
			<u-form-item label="密码" prop="userInfo.password" borderBottom ref="item1">
				<u-input v-model="model1.userInfo.password" type="password"></u-input>
			</u-form-item>
			<u-form-item label="费率" prop="userInfo.rebate" borderBottom ref="item1">
				<u-input v-model="model1.userInfo.rebate"></u-input> <span style="margin-left: 15px;">%</span>
			</u-form-item>
			<p style="font-size: 14px;color: #666;margin-top: 0px;">当前费率不得超过 {{free}} % 。</p>
		</u-form>
		<view style="margin-top: 20px;margin-bottom: 10px;" @click="submit()">
			<u-button type="primary" text="确定"></u-button>
		</view>

	</view>


</template>

<script>
	import $H from '@/common/js/request.js';
	export default {
		data() {
			return {
				model1: {
					userInfo: {
						id: '',
						name: '',
						mobile: '',
						password: '',
						rebate: '',
					},
				},
				free:''
			};
		},
		onLoad() {
			this.getData()
		},
		methods: {

			async getData() {
				try {
					const res = await $H.post('CityDistribution/user', {
					}, {
						token: true
					});
					this.Data = res.data
					this.free = res.data.level.rebate
				} catch (error) {

				} finally {}
			},

			async submit() {
				
				if(this.model1.userInfo.rebate > this.free){
					return uni.showToast({
						icon: 'none',
						title: '当前费率不得超过' + this.free + '% '
					})
				}
				
				if(this.model1.userInfo.id === ''){
					return uni.showToast({
						icon: 'none',
						title: '请完整填写内容'
					})
				}
				
				if(this.model1.userInfo.name === ''){
					return uni.showToast({
						icon: 'none',
						title: '请完整填写内容'
					})
				}
				
				if(this.model1.userInfo.mobile === ''){
					return uni.showToast({
						icon: 'none',
						title: '请完整填写内容'
					})
				}
				
				if(this.model1.userInfo.password === ''){
					return uni.showToast({
						icon: 'none',
						title: '请完整填写内容'
					})
				}
				
				if(this.model1.userInfo.rebate === ''){
					return uni.showToast({
						icon: 'none',
						title: '请完整填写内容'
					})
				}
				
				try {
					const res = await $H.post('CityDistribution/addsalesman', {
						id: this.model1.userInfo.id,
						name: this.model1.userInfo.name,
						mobile: this.model1.userInfo.mobile,
						password: this.model1.userInfo.password,
						rebate: this.model1.userInfo.rebate,
					}, {
						token: true
					});

					if (res.code == 1) {
						uni.navigateBack()
					}
					
				} catch (error) {

				} finally {}
			},
		},
	};
</script>

<style>
</style>